package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONResult;
import com.alibaba.druid.support.json.JSONUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

/**
 * 地区
 */
@Getter@Setter@ToString
public class Region extends BaseDomain {
    public static final Integer STATE_COMMON = 0; //普通
    public static final Integer STATE_HOT = 1; //推荐
    public static final Integer STATE_DISABLE = -1; //不推荐
    private String name;//名字
    private Region parent;//上一级地区
    private Integer state = STATE_COMMON;//状态,默认普通
    //讲对象转化为指定的map格式
    public Map toTreeMap(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("text",name);
        map.put("lazyLoad",true);
        if (state == 1) {
            map.put("tags",new String[]{"推荐"});
        }
        return map;
    }

    //获取json......
    public String getJSON(){
        HashMap<String, Object> map = new HashMap<>();
       // map.put("parent",parent);
        map.put("name",name);
        map.put("id",id);
        map.put("state",state);
        if (parent != null) {
            map.put("parentId",parent.getId());
            map.put("parentName",parent.getName());
        }
        return JSONUtils.toJSONString(map);
    }
}